<?php
/*
** date : 2011-2-11 ; copyright : 7OUR.COM <http://7our.com> ; author : xjay <xucj21@21cn.com>
*/
function equireModule($moduleName){
	return strtolower($moduleName)==strtolower(MODULE_NAME);
}
function equireAction($moduleName){
	return strtolower($moduleName)==strtolower(ACTION_NAME);
}
function Api($modelName){
	return D($modelName,'Api');
}
function shortUrl($url,$login = '',$appkey = '',$format = 'txt'){
	if($appkey == '')	$appkey = C('BITLY_KEY');
	if($login == '') 	$login = C('BITLY_NAME');
	$bitly = 'http://api.bit.ly/v3/shorten?longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format;

	$response = file_get_contents($bitly);
	
	if(strtolower($format) == 'json'){
		$json = @json_decode($response,true);
		return $json['results'][$url]['shortUrl'];
	}elseif(strtolower($format)=='xml'){
		$xml = simplexml_load_string($response);
		return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
	}elseif(strtolower($format)=='txt'){
		return $response;
	}
}